package com.yss.reportworld.enums;

import com.yss.common.core.enums.BaseEnum;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * 系统常量
 *
 * @author lsl
 */
@Getter
@AllArgsConstructor
public enum ReportWorldEnum implements BaseEnum<String> {
    COLUMN_TYPE("column_type", "字段类型字典值"),
    REPORT_TABLE_LAYERED("report_table_layered", "报表世界所在分层"),
    REPORT_VERSION("report_version", "报表世界版本号"),
    REPORT_DATASQL_CODE("REPORT_DATASQL_CODE", "REPORT_WORLD_DATASQL"),
    REPORT_TABLE_CODE("REPORT_TABLE_CODE", "REPORT_WORLD_TABLE"),
    REPORT_TABLE_DETAIL_CODE("REPORT_TABLE_DETAIL_CODE", "REPORT_WORLD_TABLE_DETAIL"),
    REPORT_TABLE_INDEXED_CODE("REPORT_TABLE_INDEXED_CODE", "REPORT_WORLD_TABLE_INDEXED"),
    REPORT_CUSTOMER_CODE("REPORT_CUSTOMER_CODE", "客户对应的模块和报表数据"),
    USERNAME("USERNAME", "admin"),
    PASSWORD("PASSWORD", "qwe1234!"),
    RULE_PASSWORD("123456", "规则文件生成和读取的密码"),
    CLASS_ID_A00010("A00010", "报表世界监管机构"),
    RW_DB_SUFFIX("RW_DB_", "基础信息表前缀"),
    SYS_COLUMN_NAME("CREATE_PRSN,CREATE_TIME,MDFY_PRSON,MDFY_TIME,APPROVAL_STATUS,APPROVAL_NAME,APPROVAL_TIME,REJECT_REASON,SRC_SYS",
            "系统字段，数据地图的是否不排除"),
    DATABASE_NOT_CODE("REPORT_WORLD_DATASQL,REPORT_WORLD_TABLE,REPORT_WORLD_TABLE_DETAIL,REPORT_WORLD_TABLE_INDEXED",
            "策略差异和导出的基础数据的时候排除的CODE"),
    // 基础数据页面 特殊数据的权限
    DATABASE_REPORTWORLD_SPECIAL_LIST("database:reportworld:special:list", "database:reportworld:special:list");

    private final String code;
    private final String desc;

    public static ReportWorldEnum getEnum(String code) {
        return Arrays.stream(values()).filter(b -> Objects.equals(b.code, code)).findFirst().orElse(null);
    }

    public static String getEnumDesc(String code) {
        ReportWorldEnum e = getEnum(code);
        return e != null ? e.desc : null;
    }

    /**
     * 通过code获取desc，没有的时候直接返回code
     *
     * @param code
     * @return
     */
    public static String getEnumDescByCode(String code) {
        ReportWorldEnum e = getEnum(code);
        return e != null ? e.desc : code;
    }
}
